package com.edushare.common.mailer;

import com.edushare.common.util.URLUtils;
import com.edushare.common.vo.CourseInstances;
import com.edushare.common.vo.Departments;
import com.edushare.common.vo.OutgoingEmails;
import com.edushare.common.vo.Universities;
import com.edushare.common.vo.Users;

public class ExistingUserInvite extends MailStringLoader {

	public ExistingUserInvite(Users userTo, Users userFrom, Universities univ) {
		this.userTo = userTo;
		init(userFrom, univ.getUniversityName(), URLUtils.getHomePageURL(univ));
	}

	public ExistingUserInvite(Users userTo, Users userFrom, Departments dept) {
		this.userTo = userTo;
		init(userFrom, dept.getDeptName(), URLUtils.getHomePageURL(dept));
	}

	public ExistingUserInvite(Users userTo, Users userFrom,
			CourseInstances course) {
		this.userTo = userTo;
		init(userFrom, course.getCourse().getCourseName(), URLUtils
				.getHomePageURL(course.getCourse()));

	}

	private void init(Users from, String entityName, String entityURL) {
		replaceMap.put("FROM_USER_NAME", from.getCompleteUserName());
		replaceMap.put("FROM_USER_URL", URLUtils.getHomePageURL(from));
		replaceMap.put("ENTITY_URL", entityURL);
		replaceMap.put("ENTITY_NAME", entityName);
		replaceMap.put("HOMEPAGE_URL", URLUtils.getHomePageURL(userTo));

		messageString = templateParser(mailString, replaceMap);
	}

	@Override
	public OutgoingEmails send() {
		OutgoingEmails mail = new OutgoingEmails();
		mail.setContent(messageString);
		mail.setReceiverEmailId(userTo.getEmail());
		mail.setStatus(OutgoingEmails.EMAIL_TO_BE_SENT);
		mail.setCopyType(1);
		mail.setSubject("EduShare Invitation");
		return mail;
	}

	private Users userTo = null;
	private String mailString = MailBase.get().stringMap
			.get(MailBase.EXISTING_INVITE_MAIL);

}
